<?
class paging {
	var $limit = 19;
	var $start = 1;
	var $total = 0;
	var $url = "";

	function paging($start,$total,$limit=1) {
		$this->start = $start;
		$this->total = $total;
		$this->limit = $limit;

		$this->setUrl();
	}

	function setUrl() {
		$url = split($_SERVER['PHP_SELF'],"/");
		$this->url = $url[1];
	}
	
	function showPrev() {
		$prev = $this->start - $this->limit;
		return "<a href='".$this->url."&start=$prev'>&laquo;Prev</a>\n";
	}

		
	function showNext() {
		$next = $this->start + $this->limit;
		return "<a href='".$this->url."&start=$next'>Next&raquo;</a>\n";
	}

	function getLinks() {
		if( ($this->start - $this->limit) > 0)
		$links = $links . $this->showPrev();

		$count = 1;
		$i = 1;
		
		while($count < $this->total) {
			if($count == $this->start) {
				$links = $links . '<span>'.$i.'</span>';
			} else {
				$links = $links . "<a href='".$this->url."&start=$count'>$i</a>\n";
			}
			$count = ($count + $this->limit);
			$i++;
		}

		if( ($this->start+$this->limit) < $this->total)
		$links = $links . $this->showNext();
		
		
		return $links;

	}

	function pagingText() {
		$end = ($this->start + $this->limit - 1);
		if($end > $this->total) {
			$end = $this->total;
		}
		if($this->total>0) {
		return "<span>Showing ".($this->start)." to ".($end)." of $this->total</span>";
		}
	}
};
?>